package com.itzyf.pokemondata.activity.panel

import android.content.Intent
import com.itzyf.pokemondata.R
import com.itzyf.pokemondata.bean.PokemonDo
import com.tydic.baselibrary.activity.BaseActivity
import kotlinx.android.synthetic.main.activity_zygarde.*
import kotlin.math.roundToInt

/**
 * 基格尔德
 */
class ZygardeActivity : BaseActivity() {
    private val basePanel = listOf(15311, 10805, 12180, 9561, 10478, 11002)
    private val baseSt = listOf(392, 454, 549, 367, 431, 468)
    private val baseSt2 = listOf(205, 609, 329, 494, 258, 511)
    private val baseRed1 = listOf(428, 408, 461, 361, 395, 416)

    override fun handlerActivity() {

        btnSubmit.setOnClickListener {
            val hp = getValue(etHp.text.toString())
            val pa = getValue(etPa.text.toString())
            val pd = getValue(etPd.text.toString())
            val sa = getValue(etSa.text.toString())
            val sd = getValue(etSd.text.toString())
            val speed = getValue(etSpeed.text.toString())

            val values = listOf(hp, pa, pd, sa, sd, speed)
            if (values.max()!! > 30) {
                showToast("单项种族值最大可添加30")
                return@setOnClickListener
            }
            if (values.sum() > 50) {
                showToast("种族值之和最大可添加50")
                return@setOnClickListener
            }
            val st = mutableListOf<Int>()
            val st2 = mutableListOf<Int>()
            val panel = mutableListOf<Int>()
            val red1=mutableListOf<Int>()
            for ((index, value) in values.withIndex()) {
                if (index == 0) {
                    st.add((baseSt[index] + value * 14.5).roundToInt())
                    panel.add((basePanel[index] + (value * 191.03).roundToInt()))
                } else {
                    st.add((baseSt[index] + (value * 18.13)).roundToInt())
                    panel.add((basePanel[index] + (value * 194.67)).roundToInt())
                }
                red1.add(baseRed1[index] + value * 10)
                when (index) {
                    0 -> st2.add((baseSt2[index] + value * 7.62).roundToInt())
                    1 -> st2.add((baseSt2[index] + value * 24.38).roundToInt())
                    2 -> st2.add((baseSt2[index] + value * 10.9).roundToInt())
                    3 -> st2.add((baseSt2[index] + value * 24.34).roundToInt())
                    4 -> st2.add((baseSt2[index] + value * 12.65).roundToInt())
                    5 -> st2.add((baseSt2[index] + value * 19.9).roundToInt())
                }

            }

            val intent = Intent(this@ZygardeActivity, PanelDetailActivity::class.java)
            intent.putExtra("title", "基格尔德-自定义")
            intent.putExtra("panel", panel.toIntArray())
            intent.putExtra("skin", "300,300,300,0,0,0")
            intent.putExtra("specialTraining", st.joinToString(","))
            intent.putExtra("st2", st2.joinToString(","))
            intent.putExtra("red1", red1.joinToString(","))
            startActivity(intent)
        }

    }

    fun getValue(value: String): Int {
        if (value.isEmpty()) {
            return 0
        }
        return value.toInt()
    }

    override fun getContentViewId() = R.layout.activity_zygarde

    override fun getToolbarTitle() = "基格尔德自定义"


}
